using System.Collections.Generic;
using Token = TBit.Compile.ASMCompile.Token;
using TBit.Compile;

namespace TBit.Instrcutions {
    public static class Gr {
        public static int Compile(List<Token> tokens,VM vm,int i) {
            return ASMCompile.StructureInstruction_OPCODE_R_R_R(Opcode.GR,tokens,vm,i);
        }
        public static Instruction Create(RegisterIndex a,RegisterIndex b,RegisterIndex c) {
            Instruction inst = new Instruction();
            inst.opcode = Opcode.GR;
            inst.args.Add(new InstructionArgData(a));
            inst.args.Add(new InstructionArgData(b));
            inst.args.Add(new InstructionArgData(c));
            return inst;
        }

        public static Data Calc(Data a,Data b) {
            Data data = new Data();
            switch(a.type)
            {
                case DataType.Number : {
                    switch(b.type)
                    {
                        case DataType.Number : {
                            data.type = DataType.Boolean;
                            data.boolean_data = a.number_data > b.number_data;
                        }break;
                    }
                    break;
                }
            }
            return data;
        }

        public static int Run(VM vm,Instruction inst){
            InstructionArgData arg1 = inst.args[0];
            InstructionArgData arg2 = inst.args[1];
            InstructionArgData arg3 = inst.args[2];
            Data a = vm.GetRegister(arg1.register);
            Data b = vm.GetRegister(arg2.register);
            Data v = Calc(a,b);
            vm.WriteRegister(arg3.register,v);
            return 1;
        }
    }
}